from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from starlette.requests import Request

from backend_module.jsonvo.reviews_manage_vo import BackendReviewsListQueryModel, BackendReviewsQueryModel
from backend_module.service.reviews_manage_service import ReviewsManageService
from config.get_db import get_db
from utils.response_util import response_backend_200, response_backend_400, response_backend_500

reviewsManageMapper = APIRouter()


@reviewsManageMapper.post('/reviews/list')
async def get_reviews_list(request: Request, query_model: BackendReviewsListQueryModel, db: Session = Depends(get_db)):
    results = ReviewsManageService.get_reviews_list_service(db, query_model)
    if not results:
        return response_backend_200(data='', message='没有符合条件的数据')
    else:
        return response_backend_200(data=results, message='获取成功')


@reviewsManageMapper.get('/reviews/detail')
def get_reviews_detail(request: Request, query_model: BackendReviewsQueryModel, db: Session = Depends(get_db)):
    if query_model.reviews_id == '':
        response_backend_400()
    results = ReviewsManageService.get_reviews_detail_service(db, query_model)
    if not results:
        return response_backend_500()
    else:
        return response_backend_200(data=results)
